home *** CD-ROM | disk | FTP | other *** search
- Path: newsroom.hitc.com!usenet
- From: psand@eos.hitc.com (G. Patrick Sand)
- Newsgroups: comp.lang.c++
- Subject: Re: If statements, HELP!!
- Date: 17 Jan 1996 20:09:25 GMT
- Organization: Hughes Aircraft (EOSDIS)
- Message-ID: <4djl1l$hrh@newsroom.hitc.com>
- References: <956_9601132330@medtechnet.com>
- NNTP-Posting-Host: 155.157.118.56
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.3
-
- In article <956_9601132330@medtechnet.com>,
- Tony.Johnston@dreams.medtechnet.com says...
- >
- >Can anyone see in this code fragment why this if statement wont do what
- >I need it to do. Using Borland C++ 4.0:
- >
- >
- >{
- >
- > if (SysopPercent > UserPercents) <--If this is true it should fall
- down
- > { to the next if, if false it
- should
- > go to the ELSE
- > if (SysTime < LockTime) <--If true it should process its
- > statement, if false it should
- fall
- > down to the else
- > TDDisplayFile("LOCK.ANS");
- > }
- > else
-
- 1. The else is only hit when SysopPercent <= UserPercents !!! not
- SysTime >= LockTime
- 2. Only the first call is done (TBDoors_Tmp.Open())...
-
- > TBDoors_Tmp.Open();
-
- 3. The rest is always called because it is not enclosed in a brackets
- block...
-
- > TBDoors_Tmp.Read();
- > TBDoors_Tmp.WhereTheDoorWasCalledFrom(5);
- > TBDoors_Tmp.Write();
- > TBDoors_Tmp.Close();
- >
- >
- >}
- [snip!]
-
- I BET YOU WERE EXECUTING THE TBDoors_Tmp.Open() call when the percentage
- test failed...run the debugger and step through this logic to verify...
-
- Recode along these lines:
-
- // indent and align as you like...
-
- // if it fails either condition, do the "ELSE" stuff...
- if ( ( SysopPercent <= UserPercents ) || ( SysTime >= LockTime ) )
- {
- TBDoors_Tmp.Open();
- TBDoors_Tmp.Read();
- TBDoors_Tmp.WhereTheDoorWasCalledFrom(5);
- TBDoors_Tmp.Write();
- TBDoors_Tmp.Close();
- } else
- {
- // it passed both conditions so do the desired thing...
- TDDisplayFile("LOCK.ANS");
- };
-
-
- I like to put brackets in the "THEN" and "ELSE" parts of the code even
- when they are single lines to avoid such problems as these...
-
- That should fix it, if I understood things correctly...
- --
- G. Patrick Sand
- psand@eos.hitc.com
- PatSand@aol.com
- (301) 925-0791
- "Travel Light But Right..."
- Microsoft Network is prohibited from redistributing
- this work in any form, in whole or in part. License
- to distribute this individual post is available to Microsoft
- for $999. Posting without permission constitutes an
- agreement to these terms...gps
-
-